/**
 * Created by yuyongzhen  <1640599564@qq.com>>.
 */

module.exports = function(mod, name) {

	mod.controller(name, ['$scope', 'topListService', '$http', '$timeout', function($scope, topListService, $http, $timeout) {
		$scope.title = "主题编辑";
		$scope.createCancelBtnName = "save";

		$scope.topListService = topListService;
		//修改列表
		$scope.editSite = function() {
			$scope.topListService.redirectPage("/topic/topicedit");
			//			$scope.topListService.angularCallAjax('post', 'http://172.16.10.120:33333/api/sites/edit?', {
			//				id: this.data.id,
			//				name: this.data.name,
			//				avg_interval: this.data.avg_interval
			//			});
			$scope.editId = this.data.id;
			$scope.editName = this.data.name;
			$scope.editAvgInterval = this.data.avg_interval;
			$timeout(
				function() {
					document.getElementById("topic-id").value = $scope.editId;
					document.getElementById("topic-name").value = $scope.editName;
					document.getElementById("topic-intr").value = $scope.editAvgInterval;
				},
				500
			);
		};

		//保存更改
		$scope.saveEditSite = function() {
			$http({
				method: 'post',
				url: '/api/sites/edit',
				params: {
					id: document.getElementById("topic-id").value,
					name: document.getElementById("topic-name").value,
					avg_interval: document.getElementById("topic-intr").value
				}
			}).
			success(function(data, status, headers, config) {
				console.log(data);
			}).error(function(data, status, headers, config) {
				console.log("FAIL");
			});
		};

		$scope.angularCallAjax = function(method, reqUrl, params) {
			$http({
				method: method,
				url: reqUrl,
				params: params
			}).
			success(function(data, status, headers, config) {
				console.log(data);
				$scope.listArray = data.data;

			}).error(function(data, status, headers, config) {
				console.log("FAIL");
			});
		};

		$scope.init = $scope.angularCallAjax('GET', '/api/sites/entry?', {
			pageno: 2
		});

	}]);
}
